<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="设备总状态:">
              <a-select
                v-model:value="where.deviceTotalStatus"
                placeholder="请选择状态"
                style="width: 205px;"
              >
                <a-select-option value="0">所有状态正常</a-select-option>
                <a-select-option value="1">存在异常</a-select-option>
                <a-select-option value="2">传感器信息错误</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>

          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="dltwdId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          v-model:selection="selection"
          :scroll="{ x: 'max-content' }"
        >
          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>

            <template v-if="column.key === 'deviceStatusChaixieColumn'">
              <a-tag v-if="record.deviceStatusChaixie == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">设备没有正常安装</a-tag>
            </template>

            <template v-if="column.key === 'deviceStatusWarnColumn'">
              <a-tag v-if="record.deviceStatusWarn == 0" color="green">无</a-tag>
              <a-tag v-else color="red">有</a-tag>
            </template>

            <template v-if="column.key === 'deviceStatusPressColumn'">
              <a-tag v-if="record.deviceStatusPress == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">欠压</a-tag>
            </template>


            <template v-if="column.key === 'deviceStatusEleColumn'">
              <a-tag v-if="record.deviceStatusEle == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">故障</a-tag>
            </template>

            <template v-if="column.key === 'deviceStatusErrorColumn'">
              <a-tag v-if="record.deviceStatusError == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">故障</a-tag>
            </template>

            <template v-if="column.key === 'sensorStatusColumn'">
              <a-tag v-if="record.sensorStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">故障</a-tag>
            </template>

            <template v-if="column.key === 'aVoltageStatusColumn'">
              <a-tag v-if="record.avoltageStatus == 0" color="green">正常</a-tag>
              <a-tag v-else-if="record.avoltageStatus == 1" color="red">超上限</a-tag>
              <a-tag v-else color="red">超下限</a-tag>
            </template>

            <template v-if="column.key === 'bVoltageStatusColumn'">
              <a-tag v-if="record.bvoltageStatus == 0" color="green">正常</a-tag>
              <a-tag v-else-if="record.bvoltageStatus == 1" color="red">超上限</a-tag>
              <a-tag v-else color="red">超下限</a-tag>
            </template>

            <template v-if="column.key === 'cVoltageStatusColumn'">
              <a-tag v-if="record.cvoltageStatus == 0" color="green">正常</a-tag>
              <a-tag v-else-if="record.cvoltageStatus == 1" color="red">超上限</a-tag>
              <a-tag v-else color="red">超下限</a-tag>
            </template>

            <template v-if="column.key === 'aCurrentStatusColumn'">
              <a-tag v-if="record.acurrentStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">过载</a-tag>
            </template>

            <template v-if="column.key === 'bCurrentStatusColumn'">
              <a-tag v-if="record.bcurrentStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">过载</a-tag>
            </template>

            <template v-if="column.key === 'cCurrentStatusColumn'">
              <a-tag v-if="record.ccurrentStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">过载</a-tag>
            </template>

            <template v-if="column.key === 'leakageCurrentStatusColumn'">
              <a-tag v-if="record.leakageCurrentStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">漏电</a-tag>
            </template>

            <template v-if="column.key === 'aFireTemperatureStatusColumn'">
              <a-tag v-if="record.afireTemperatureStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">超上限</a-tag>
            </template>

            <template v-if="column.key === 'bFireTemperatureStatusColumn'">
              <a-tag v-if="record.bfireTemperatureStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">超上限</a-tag>
            </template>

            <template v-if="column.key === 'cFireTemperatureStatusColumn'">
              <a-tag v-if="record.cfireTemperatureStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">超上限</a-tag>
            </template>

            <template v-if="column.key === 'zeroTemperatureStatusColumn'">
              <a-tag v-if="record.zeroTemperatureStatus == 0" color="green">正常</a-tag>
              <a-tag v-else color="red">超上限</a-tag>
            </template>

            <template v-if="column.key === 'remoteLockColumn'">
              <a-tag v-if="record.remoteLock == 0" color="green">解锁</a-tag>
              <a-tag v-else color="red">锁扣</a-tag>
            </template>

            <template v-if="column.key === 'controlModelColumn'">
              <a-tag v-if="record.controlModel == 0" color="green">自动</a-tag>
              <a-tag v-else color="red">手动</a-tag>
            </template>

            <template v-if="column.key === 'outputStatusColumn'">
              <a-tag v-if="record.outputStatus == 1" color="green">合闸</a-tag>
              <a-tag v-else color="red">分闸</a-tag>
            </template>

          </template>
        </ele-pro-table>
      </a-card>
    </div>
  </div>

</template>

<script>
import { DeviceLuoxunThreephaseWarnDataApi } from '@/api/property/DeviceLuoxunThreephaseWarnDataApi';
import { message } from 'ant-design-vue';

export default {
  name: 'DeviceLuoxunThreephaseWarnData',
  components: {

  },
  async mounted() {
  },
  props: {
    data: Object
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '上报时间',
          dataIndex: 'uploadTime'
        },
        {
          title: '设备安装状态',
          dataIndex: 'deviceStatusChaixie',
          key : 'deviceStatusChaixieColumn'
        },
        {
          title: '是否有报警信号',
          dataIndex: 'deviceStatusWarn',
          key : 'deviceStatusWarnColumn'
        },
        {
          title: '主电池状态',
          dataIndex: 'deviceStatusPress',
          key : 'deviceStatusPressColumn'
        },
        {
          title: '电源状态',
          dataIndex: 'deviceStatusEle',
          key : 'deviceStatusEleColumn'
        },
        {
          title: '设备是否有故障',
          dataIndex: 'deviceStatusError',
          key : 'deviceStatusErrorColumn'
        },
        {
          title: '传感器故障',
          dataIndex: 'sensorStatus',
          key : 'sensorStatusColumn'
        },
        {
          title: 'A-电压状态',
          dataIndex: 'avoltageStatus',
          key : 'aVoltageStatusColumn'
        },
        {
          title: 'B-电压状态',
          dataIndex: 'bvoltageStatus',
          key : 'bVoltageStatusColumn'
        },
        {
          title: 'C-电压状态',
          dataIndex: 'cvoltageStatus',
          key : 'cVoltageStatusColumn'
        },
        {
          title: 'A-电流状态',
          dataIndex: 'acurrentStatus',
          key: 'aCurrentStatusColumn'
        },
        {
          title: 'B-电流状态',
          dataIndex: 'bcurrentStatus',
          key: 'bCurrentStatusColumn'
        },
        {
          title: 'C-电流状态',
          dataIndex: 'ccurrentStatus',
          key: 'cCurrentStatusColumn'
        },
        {
          title: '漏电流状态',
          dataIndex: 'leakageCurrentStatus',
          key : 'leakageCurrentStatusColumn'
        },
        {
          title: 'A-火线温度',
          dataIndex: 'afireTemperatureStatus',
          key : 'aFireTemperatureStatusColumn'
        },
        {
          title: 'B-火线温度',
          dataIndex: 'bfireTemperatureStatus',
          key : 'bFireTemperatureStatusColumn'
        },
        {
          title: 'C-火线温度',
          dataIndex: 'cfireTemperatureStatus',
          key : 'cFireTemperatureStatusColumn'
        },
        {
          title: '零线温度',
          dataIndex: 'zeroTemperatureStatus',
          key : 'zeroTemperatureStatusColumn'
        },
        {
          title: '远程锁扣',
          dataIndex: 'remoteLock',
          key : 'remoteLockColumn'
        },
        {
          title: '控制模式',
          dataIndex: 'controlModel',
          key: 'controlModelColumn'
        },
        {
          title: '输出状态',
          dataIndex: 'outputStatus',
          key : 'outputStatusColumn'
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
        }
      ],
      // 表格搜索条件
      where: {"recordId" : this.data.recordId},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    reset() {
      this.where.recordId = this.data.recordId;
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.where.deviceTotalStatus = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    async remove(row) {
      const result = await DeviceLuoxunThreephaseWarnDataApi.delete({ dltwdId: row.dltwdId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return DeviceLuoxunThreephaseWarnDataApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    },
  }
};
</script>
